<?php
class JHTMLFarm
{
	/**
	 * 农场下拉菜单
	 */
	function fieldDropList($selected = 0)
	{
		$field = JTable::getInstance('field', 'Table');
		$data = $field->dataForOptions();
		?>
		 <tr>
			<td width="120" class="key">
				农场编号:
			</td>
			<td>				
				<select name="fid" id="fid" class="required">
					<option value="" <?php if ($selected == 0) echo "selected='true'";?>>选择农场</option>
					<?php foreach ($data as $item):?>
					<option value="<?php echo $item['id'];?>" <?php if ($selected == $item['id']) echo "selected='true'";?>><?php echo $item['no'];?></option>
					<?php endforeach;?>
				</select>
			</td>
			
		</tr>
		<?php
	}
	
	/**
	 * 植物下拉菜单
	 */
	function plantDropList($selected = 0)
	{
		$field = JTable::getInstance('plant', 'Table');
		$data = $field->dataForOptions();
		?>
		 <tr>
			<td width="120" class="key">
				植物编号:
			</td>
			<td>				
				<select name="pid" id="pid" class="required">
					<option value="" <?php if ($selected == 0) echo "selected='true'";?>>选择植物</option>
					<?php foreach ($data as $item):?>
					<option value="<?php echo $item['id'];?>" <?php if ($selected == $item['id']) echo "selected='true'";?>><?php echo $item['no'];?></option>
					<?php endforeach;?>
				</select>
			</td>
			
		</tr>
		<?php
	}
	
	/**
	 * 用户下拉菜单
	 */
	function userDropList($selected = 0)
	{
		$db	= JFactory::getDBO();
		$query = 'SELECT id, name no' .
				' FROM #__users';
		$db->setQuery($query);
		$data = $db->loadAssocList();
		?>
		 <tr>
			<td width="120" class="key">
				计录人员:
			</td>
			<td>				
				<select name="uid" id="uid" class="required">
					<option value="" <?php if ($selected == 0) echo "selected='true'";?>>选择人员</option>
					<?php foreach ($data as $item):?>
					<option value="<?php echo $item['id'];?>" <?php if ($selected == $item['id']) echo "selected='true'";?>><?php echo $item['no'];?></option>
					<?php endforeach;?>
				</select>
			</td>
			
		</tr>
		<?php
	}
	
	/**
	 * 肥料下拉菜单
	 */
	function manureDropList($selected = 0)
	{
		$field = JTable::getInstance('manure', 'Table');
		$data = $field->dataForOptions();
		?>
		<select name="manure[0]" id="manure_select_0" class="manureSelect">
			<option value="" <?php if ($selected == 0) echo "selected='true'";?>>选择肥料</option>
			<?php foreach ($data as $item):?>
			<option value="<?php echo $item['id'];?>" <?php if ($selected == $item['id']) echo "selected='true'";?>><?php echo $item['no'];?></option>
			<?php endforeach;?>
		</select>
		<?php
	}
	
	/**
	 * 农药下拉菜单
	 */
	function pesticideDropList($selected = 0)
	{
		$field = JTable::getInstance('pesticide', 'Table');
		$data = $field->dataForOptions();
		?>
		<select name="pesticide[0]" id="pesticide_select_0" class="pesticideSelect">
			<option value="" <?php if ($selected == 0) echo "selected='true'";?>>选择农药</option>
			<?php foreach ($data as $item):?>
			<option value="<?php echo $item['id'];?>" <?php if ($selected == $item['id']) echo "selected='true'";?>><?php echo $item['no'];?></option>
			<?php endforeach;?>
		</select>
		<?php
	}
	
	/**
	 * 观测站下拉菜单 
	 */
	function obserDropList($selected = 0, $showWrap = true)
	{
		$field = JTable::getInstance('obser', 'Table');
		$data = $field->dataForOptions();
		
		if (!empty($_GET['oid'])) $selected = intval($_GET['oid']);
		
		if ($showWrap):
		?>
		<tr>
			<td width="120" class="key">观测站:	</td>
			<td>
		<?php
		endif;
		?>				
				<select name="oid" id="oid" class="required" <?php if (!$showWrap):?>onchange="location.href=location.href.replace(/\&oid=\d*/g, '') + '&oid=' + this.value"<?php endif;?>>
					<option value="" <?php if ($selected == 0) echo "selected='true'";?>>选择观测站</option>
					<?php foreach ($data as $item):?>
					<option value="<?php echo $item['id'];?>" <?php if ($selected == $item['id']) echo "selected='true'";?>><?php echo $item['no'];?></option>
					<?php endforeach;?>
				</select>
			</td>			
		</tr>
		<?php
	}
	
	/**
	 * 种植计划下拉菜单 
	 */
	function plantPlanDropList($selected = 0, $showWrap = true)
	{
		$field = JTable::getInstance('plantPlan', 'Table');
		$data = $field->dataForOptions();
		
		if (!empty($_GET['ppid'])) $selected = intval($_GET['ppid']);
		
		if ($showWrap):
		?>
		<tr>
			<td width="120" class="key">种植计划:	</td>
			<td>
		<?php
		endif;
		?>
				<select name="ppid" id="ppid" class="required"  <?php if (!$showWrap):?>onchange="location.href=location.href.replace(/\&ppid\=\d*/g, '') + '&ppid=' + this.value"<?php endif;?>>
					<option value="" <?php if ($selected == 0) echo "selected='true'";?>>请选择种植计划</option>
					<?php foreach ($data as $item):?>
					<option value="<?php echo $item['id'];?>" <?php if ($selected == $item['id']) echo "selected='selected'";?>><?php echo $item['no'];?></option>
					<?php endforeach;?>
				</select>
		<?php if ($showWrap):?>
			</td>			
		</tr>
		<?php endif;
	}
	
	/**
	 * 病虫害菜单 
	 */
	function diseaseDropList($checked = array())
	{
		$field = JTable::getInstance('disease', 'Table');
		$data = $field->getAll('', 'id, name');
		if (!$data) return;
		?>
		<tr>
			<td width="120" class="key">病虫害:	</td>
			<td>
				<?php foreach ($data as $v) { ?>
				<label><input type="checkbox" name='dids[]' <?php if (in_array($v['id'], $checked)) echo "checked='true'";?> value="<?php echo $v['id']?>" /><?php echo $v['name'];?></label> &nbsp;&nbsp;&nbsp;
				<?php } ?>
			</td>			
		</tr>
		<?php
	}
}